package com.kingdee.pda.ui.scan_outwarehouse;

import android.content.Context;

import com.example.basecommon.http.MyObserver;
import com.example.basecommon.http.RxHelper;
import com.example.basecommon.http.rxjava.BaseResponse;
import com.example.basecommon.http.rxjava.HttpUtils;
import com.example.basecommon.utils.ConstantUtil;
import com.kingdee.pda.Api;
import com.kingdee.pda.entity.ScanOutOrderInfoBean;

import java.util.HashMap;

/**
 * @author：dlj
 * @data：2021/9/22:10:31
 * @des：扫描出库Presenter
 */
public class ScanOutWarehousePresenter implements ScanOutWarehouseContract.IScanOutWarehousePresenter {
    private Context context;
    private ScanOutWarehouseContract.IScanOutWarehouseView view;

    public ScanOutWarehousePresenter(Context context, ScanOutWarehouseContract.IScanOutWarehouseView view) {
        this.context = context;
        this.view = view;
    }

    @Override
    public void scanStockOutBillOrExpressNo(String scanbillno) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("scanbillno", scanbillno);
        map.put("review", false);

        MyObserver<ScanOutOrderInfoBean> myObserver = new MyObserver<ScanOutOrderInfoBean>(context,false) {
            @Override
            public void onSuccess(BaseResponse<ScanOutOrderInfoBean> result) {
                view.scanStockOutBillOrExpressNoSuccess(result.data);
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
                view.scanStockOutBillOrExpressNoFailed(result.message);
            }
        };
        HttpUtils.request(Api.class)
                .scanStockOutBillOrExpressNo(ConstantUtil.SCANORDERNO, map)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(myObserver);
    }

    @Override
    public void confirmStockOut(String id, String formId, String numberType, String number) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("type", 2);//pda出库type固定2
        map.put("formId", formId);
        map.put("numberType", numberType);
        map.put("number", number);

        MyObserver myObserver = new MyObserver(context,false) {
            @Override
            public void onSuccess(BaseResponse result) {
                view.confirmStockOutResult(true, result.message);
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
                view.confirmStockOutResult(false, result.message);
            }
        };
        HttpUtils.request(Api.class)
                .confirmStockOut(ConstantUtil.CONFIRMSTOCKOUT, map)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(myObserver);
    }
}
